package com.sctu.adapter;

import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.sctu.EMSApp.PlayAmuseMoreListActivity;
import com.sctu.EMSApp.PlayAmuseOneDetailsActivity;
import com.sctu.EMSApp.R;

import com.sctu.bean.PlayAmuseListOne;
import com.sctu.http.UrlConfig;
import com.sctu.httpvollry.GetVolleyHttp;

import java.util.List;

/**
 * Created by zhengsenwen on 2015/12/17.
 */
public class PlayAmuseListviewAdapter extends BaseAdapter {

    //头部控件
    private TextView listitemhead;
    private TextView listitemmore;
    //展示的第一个娱乐
    private ImageView listitemoneimg;
    private TextView listitemonetext;
    //展示的第二个娱乐
    private ImageView listitemtwoimg;
    private TextView listitemtwotext;
    //展示的第三个娱乐
    private ImageView listitemthreeimg;
    private TextView listitemthreetext;

    private List<PlayAmuseListOne.Results> list;
    private Activity context;

    public PlayAmuseListviewAdapter(Activity context, List<PlayAmuseListOne.Results> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        if (list != null && list.size() > 0) {
            return list.size();
        } else {
            return 0;
        }
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_play_amuse, null);

        listitemhead = (TextView) view.findViewById(R.id.item_play_amuse_category_text);
        listitemmore = (TextView) view.findViewById(R.id.item_play_amuse_more_text);

        listitemoneimg = (ImageView) view.findViewById(R.id.item_play_amuse_one_img);
        listitemonetext = (TextView) view.findViewById(R.id.item_play_amuse_one_text);

        listitemtwoimg = (ImageView) view.findViewById(R.id.item_play_amuse_two_img);
        listitemtwotext = (TextView) view.findViewById(R.id.item_play_amuse_two_text);

        listitemthreeimg = (ImageView) view.findViewById(R.id.item_play_amuse_three_img);
        listitemthreetext = (TextView) view.findViewById(R.id.item_play_amuse_three_text);

        listitemhead.setText(list.get(position).getName());
        listitemmore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(context, PlayAmuseMoreListActivity.class);
                intent.putExtra("uuid_amuse", list.get(position).getUuid());
                context.startActivity(intent);

            }
        });
        GetVolleyHttp.getInstance(context).setImageLoader(listitemoneimg, R.drawable.error_image,
                R.drawable.error_image, UrlConfig.URL + list.get(position).getArticleList().get(0).getPath());
        listitemonetext.setText(list.get(position).getArticleList().get(0).getTitle());
        listitemoneimg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(context, PlayAmuseOneDetailsActivity.class);
                intent.putExtra("id_amuse", list.get(position).getArticleList().get(0).getId());
                context.startActivity(intent);
            }
        });

        GetVolleyHttp.getInstance(context).setImageLoader(listitemtwoimg, R.drawable.error_image,
                R.drawable.error_image, UrlConfig.URL + list.get(position).getArticleList().get(1).getPath());
        listitemtwotext.setText(list.get(position).getArticleList().get(1).getTitle());
        listitemtwoimg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(context, PlayAmuseOneDetailsActivity.class);
                intent.putExtra("id_amuse", list.get(position).getArticleList().get(1).getId());
                context.startActivity(intent);
            }
        });

        GetVolleyHttp.getInstance(context).setImageLoader(listitemthreeimg, R.drawable.error_image,
                R.drawable.error_image, UrlConfig.URL + list.get(position).getArticleList().get(2).getPath());
        listitemthreetext.setText(list.get(position).getArticleList().get(2).getTitle());
        listitemthreeimg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(context, PlayAmuseOneDetailsActivity.class);
                intent.putExtra("id_amuse", list.get(position).getArticleList().get(2).getId());
                context.startActivity(intent);
            }
        });

        return view;
    }
}
